package com.example.accessibilityhelper.group

import android.accessibilityservice.AccessibilityService
import android.view.accessibility.AccessibilityEvent
import com.example.accessibilityhelper.Step
import com.example.accessibilityhelper.util.click
import com.example.accessibilityhelper.util.findAccessibilityNodeByShortViewId

class Step1GotoCustomerServicePage: Step() {
    override fun match(service: AccessibilityService, event: AccessibilityEvent): Boolean {
        val recyclerViewNode =
           service.rootInActiveWindow?.findAccessibilityNodeByShortViewId("s8")
        return event.className == "androidx.recyclerview.widget.RecyclerView" && recyclerViewNode?.isNotEmpty()  == true
    }

    override fun execute(service: AccessibilityService, event: AccessibilityEvent) {
        val recyclerViewNode =
            service.rootInActiveWindow?.findAccessibilityNodeByShortViewId("s8")
        recyclerViewNode?.firstOrNull()?.getChild(1)?.click()
        finish()
    }
}